#include "http_cli.c"

#include "utils.c"
#include <string.h>

Error *e;
struct HttpReq req;

#define __env__ {\
    req.body.data = "POST";\
    req.body.dsiz = sizeof("POST") - 1;\
    req.body.drop = nil;\
\
    e = nil;\
\
    req.url = "http://www.163.com";\
    req.method = "GET";\
    req.headers = nil;\
    req.nheaders = 0;\
    req.status_code = -1;\
};

void
get(void){
    __env__
    e = httpcli.req(&req);
    if(nil != e){
        __display_and_fatal(e);
    }
    req.body.drop(&req.body);
    SoN(200, req.status_code);
}

void
post(void){
    __env__
    req.method = "POST";
    e = httpcli.req(&req);
    if(nil != e){
        __display_and_fatal(e);
    }
    req.body.drop(&req.body);
    SoN(200, req.status_code);
}

void
bad_req_invalid_body_siz(void){
    //test bad request info
    __env__
    req.url = "http://localhost:9000/body_add_one";
    req.body.dsiz = 1000000000;
    if(nil != (e = httpcli.req(&req))){
        __clean_errchain(e);
    }
    So(-1, req.status_code);
    So(utils.non_drop, req.body.drop);
    req.body.drop(&req.body);
}

_i
main(void){
    get();
    post();
    bad_req_invalid_body_siz();
}
